import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;

public class ClientAes {
    public static void main(String[] args) throws IOException {
        try {
            //Socket socket = new Socket("10.1.1.234", 5218);
            Socket socket = new Socket("10.1.1.230", 5223);
            System.out.println("客户端启动成功！");
            System.out.println("请输入中缀表达式：");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter write = new PrintWriter(socket.getOutputStream());
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String expression;

            MyBC bc = new MyBC();
            expression = br.readLine();
            String input =new String();
            String input2 = new String();

            input = bc.toSuffix("1+(4*2)/2+5+4*3-4");
            AesEncodeUtil aes = new AesEncodeUtil();
            input2 = aes.encrypt(input);
            //创建对象aes，并调用 AesEncodeUtil 类中的加密方法
            while (!expression.equals("end")) {
                write.println(input2);
                write.println(expression);
                write.flush();
                System.out.println("aes加密的后缀表达式为:" );
                System.out.println("服务器返回值为:" + in.readLine());
                expression = br.readLine();
            }
            write.close();
            in.close();
            socket.close();
        } catch (Exception e) {
            System.out.println("无法监听:" + e);
        }
    }
}
